package com.gemfire.onlineretailer.domain;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Date;

import com.gemstone.gemfire.DataSerializable;
import com.gemstone.gemfire.DataSerializer;

public class Disk extends Item implements DataSerializable {

	  public static final long DISK_1 = 10000001;
	  public static final long DISK_2 = 10000002;

	  public static final long DISK_3 = 10000003;
	  public static final long DISK_4 = 10000004;
	  public static final long DISK_5 = 10000005;
	  
	  public static final String DISK_1_CODE = "10000001";
	  public static final String DISK_2_CODE = "10000002";

	  public static final String DISK_3_CODE = "10000003";
	  public static final String DISK_4_CODE = "10000004";
	  public static final String DISK_5_CODE = "10000005";
	  
	  public static final String DISK_1_COLOR = "Red";
	  public static final String DISK_2_COLOR = "Yelow";
	  public static final String DISK_3_COLOR = "Blue";
	  public static final String DISK_4_COLOR = "Purple";
	  public static final String DISK_5_COLOR = "White";
	  
	  public static final String DISK_1_ARTIST = "John Mayer";
	  public static final String DISK_2_ARTIST = "Talor Swift";
	  public static final String DISK_3_ARTIST = "Selena Gomez";
	  public static final String DISK_4_ARTIST = "Michel Jacjson";
	  public static final String DISK_5_ARTIST = "Beettles";
	  
	  public static final String DISK_1_TITLE = "John Mayer Collection";
	  public static final String DISK_2_TITLE = "Talor Swift Collection";
	  public static final String DISK_3_TITLE = "Selena Gomez Collection";
	  public static final String DISK_4_TITLE = "Beettles Collection";
	  public static final String DISK_5_TITLE = "Michel Jacjson Collection";

	  
	  public static final float DISK_1_ORIGNAL_PRICE = 28.00f;
	  public static final float DISK_2_ORIGNAL_PRICE = 30.00f ;
	  public static final float DISK_3_ORIGNAL_PRICE = 32.00f;
	  public static final float DISK_4_ORIGNAL_PRICE = 34.00f;
	  public static final float DISK_5_ORIGNAL_PRICE = 36.00f;
	  
	  public static final float DISK_1_DICCOUNT_PRICE = 20.00f;
	  public static final float DISK_2_DICCOUNT_PRICE = 25.00f ;
	  public static final float DISK_3_DICCOUNT_PRICE = 27.00f;
	  public static final float DISK_4_DICCOUNT_PRICE = 24.00f;
	  public static final float DISK_5_DICCOUNT_PRICE = 23.00f;
	  
	  
	private String title;
	private String artist;
	private Date releaseDate;
	private int numSongs;
	private float price;
	
	
	public Disk(){
		
	}
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getArtist() {
		return artist;
	}

	public void setArtist(String artist) {
		this.artist = artist;
	}

	public Date getReleaseDate() {
		return releaseDate;
	}

	public void setReleaseDate(Date releaseDate) {
		this.releaseDate = releaseDate;
	}

	public int getNumSongs() {
		return numSongs;
	}

	public void setNumSongs(int numSongs) {
		this.numSongs = numSongs;
	}

	public float getPrice() {
		return price;
	}

	public void setPrice(float price) {
		this.price = price;
	}

	@Override
	public void fromData(DataInput in) throws IOException,
			ClassNotFoundException {
	
		this.title = in.readUTF();
		this.artist = in.readUTF();
		this.releaseDate = DataSerializer.readDate(in);
		this.numSongs = in.readInt();
		this.price = in.readFloat();
		
	}

	@Override
	public void toData(DataOutput out) throws IOException {
		out.writeUTF(this.title);
		out.writeUTF(this.artist);
		DataSerializer.writeDate(this.releaseDate, out);
		out.writeInt(this.numSongs);
		out.writeFloat(this.price);
	}
	
public static Disk createInstance(long diskId){
		
		/*
		 * Use itemId to read from DB or from other source, Hardcode for now
		 */
		
		Disk disk = new Disk();
		
		if (diskId == DISK_1){
			disk.setItemId(diskId);
			disk.setArtist(DISK_1_ARTIST);
			disk.setTitle(DISK_1_TITLE);
			disk.setItemCode(DISK_1_CODE);
			disk.setReorderLevel(20);
		} 
		else if (diskId == DISK_2){
			disk.setItemId(diskId);
			disk.setArtist(DISK_2_ARTIST);
			disk.setTitle(DISK_2_TITLE);
			disk.setItemCode(DISK_2_CODE);
			disk.setReorderLevel(30);
		} 
		else if (diskId == DISK_3){
			disk.setItemId(diskId);
			disk.setArtist(DISK_3_ARTIST);
			disk.setTitle(DISK_3_TITLE);
			disk.setItemCode(DISK_3_CODE);
			disk.setReorderLevel(40);
		} 
		else if (diskId == DISK_4){
			disk.setItemId(diskId);
			disk.setArtist(DISK_4_ARTIST);
			disk.setTitle(DISK_4_TITLE);
			disk.setItemCode(DISK_4_CODE);
			disk.setReorderLevel(50);
		}
		else {
			disk.setItemId(diskId);
			disk.setArtist(DISK_5_ARTIST);
			disk.setTitle(DISK_5_TITLE);
			disk.setItemCode(DISK_5_CODE);
			disk.setReorderLevel(50);
	
			} 
		
		return disk;
		
	}

}
